import time
import paramunittest
import unittest
import HTMLTestRunner

from woniuBoss_Interface_Test.Data_module.get_Data import get_Test_data
from woniuBoss_Interface_Test.Contronl_module.run_test import run_test

# 数据驱动
file = '../Data_module/接口测试-培训资源-搜索.csv'
Data = get_Test_data(file).getdata()


@paramunittest.parametrized(
    *Data,
)
class TestFoo(paramunittest.ParametrizedTestCase):
    @classmethod
    def setUpClass(cls):
        print('begin')

    def setParameters(self, pageSize, pageIndex, status, cusInfo, lastStatus, empName, source, s_time, e_time,
                      poolType):
        self.pageSize = pageSize
        self.pageIndex = pageIndex
        self.status = status
        self.cusInfo = cusInfo
        self.lastStatus = lastStatus
        self.empName = empName
        self.source = source
        self.s_time = s_time
        self.e_time = e_time
        self.poolType = poolType

    def testLess(self):
        a = {'pageSize': self.pageSize, 'pageIndex': self.pageIndex, 'status': self.status, 'cusInfo': self.cusInfo,
             'lastStatus': self.lastStatus, 'empName': self.empName, 'source': self.source,
             's_time': self.s_time, 'e_time': self.e_time, 'poolType': self.poolType}
        run_test(a).run_T()
        # self.assertLess(self.a, self.b)

    @classmethod
    def tearDownClass(cls):
        print('end')


if __name__ == '__main__':
    test_dir = '.'
    suite = unittest.defaultTestLoader.discover(test_dir, pattern='paramunittest_run.py')
    now_time = time.strftime('%Y%m%d%H%M%S接口测试结果', time.localtime(time.time()))
    filename = '../Testresult/' + now_time + '.html'
    # filename = '../' + now_time + '.html'
    with open(filename, 'wb') as fp:
        runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'测试报告', description=u'用例执行情况：')
        runner.run(suite)
